//
//  GroupMemberViewController.m
//  NuwaRobot
//
//  Created by Kendama on 2017/12/12.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "GroupMemberViewController.h"
#import "HomeCollectionViewCell.h"
#import "FriendModel.h"

@interface GroupMemberViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong) UICollectionView *collectionView;
@property(nonatomic,strong) NSArray *dataSource;
@property(nonatomic,strong) NSArray *group;

@end

@implementation GroupMemberViewController

- (instancetype)initWithGroup:(NSArray *)group
{
    self = [self init];
    if (self) {
        _group = group;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

#pragma mark - UICollectionViewDelegate,UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.group.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeCollectionViewCell *cell = [HomeCollectionViewCell cellWithCollectionView:collectionView forIndexPath:indexPath];
    
    FriendModel *model = self.group[indexPath.row];
    cell.titleLabel.text = model.nickname;
    NSString *url = [NSString stringWithFormat:@"%@%@",self.domain,model.image];
    [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:imageWithName(@"icon_head")];
    if ([model.nickname isEqualToString:@""])
    {
        cell.titleLabel.text = @"我的机器人";
        cell.iconImageView.image = imageWithName(@"robot_head");
    }
    cell.badgeLabel.hidden = YES;
    //    cell.backgroundColor = indexPath.row %2 ? [UIColor redColor] : [UIColor blueColor];
    return cell;
}



#pragma mark --- 懒加载
- (NSArray *)dataSource
{
    if (!_dataSource)
    {
        _dataSource = @[@[@"拨打电话",@"家居控制",@"实时监控",@"设置",@"提醒",@"消息"],@[@"iPhone",@"home",@"monitoring",@"set",@"remind",@"news"]];
    }
    return _dataSource;
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(px1080Width(1000)/4 - 8 , px1920Height(601)/2 - 4);
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        layout.sectionInset = UIEdgeInsetsMake(6, 6, 6, 6);
        _collectionView = ({
            UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
            collectionView.scrollEnabled = NO;
            collectionView.backgroundColor = rgba(27,44,81,1);
            collectionView.delegate = self;
            collectionView.dataSource = self;
            [self.view addSubview:collectionView];
            collectionView;
        });
    }return _collectionView;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self.view;
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(252));
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.width.mas_equalTo(px1080Width(1000));
        make.bottom.mas_equalTo(superView.mas_bottom).with.offset(-px1920Height(40));
    }];
}

- (void)setNavigationStyle
{
    [self setNavigationBarTitle:@"群成员"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
